package game;

import javax.microedition.lcdui.game.LayerManager;

public abstract class Unit {

	static double TAN_15 = 0.26794919243112270647255365849413;
	static double TAN_45 = 1;
	static double TAN_75 = 3.7320508075688772935274463415059;
	
	protected double MAX_HP=100;
	protected double hp;
	protected double attack;
	protected double defend;
	protected double positionX;
	protected double positionY;
	
	public void update(){
		
	}
	public void init(int x,int y){
		
	}
	public void addToLayer(LayerManager layer){
		
	}
	
	
	public int getX() {
		return (int)positionX;
	}
	public int getY() {
		return (int)positionY;
	}
	public void run(int x,int y){
		
	}
	
	public void fire(int x,int y){
		
	}
	public double arc(int x, int y) {
		double xn, yn, arc;
		if (x >= 0 && y < 0) {
			xn = -y;
			yn = x;
			arc = 0;
		} else if (x >= 0 && y >= 0) {
			xn = x;
			yn = y;
			arc = 90;
		} else if (x < 0 && y >= 0) {
			xn = y;
			yn = -x;
			arc = 180;
		} else {
			xn = -x;
			yn = -y;
			arc = 270;
		}
		if (yn == 0) {
			return arc;
		}
		double tan = yn / xn;
		if (tan > TAN_75) {
			arc += 90;
		} else if (tan > TAN_45) {
			arc += 60;
		} else if (tan > TAN_15) {
			arc += 30;
		}
		if(arc>=360)
		{
			arc-=360;
		}
		return arc;
	}
}
